'use strict'

const Service = require('egg').Service;

class dlqcenter extends Service {
    async findAll() {
        const result = await this.app.mysql.select('dlqcenter');
        return {
            code: 200,
            msg: '查找成功',
            data: result
        };
    }
    async findAllOrder() {
        const result = await this.app.mysql.select('dlqorders');
        return {
            code: 200,
            msg: '查找成功',
            data: result
        };
    }
    async findAllMygoods() {
        const result = await this.app.mysql.select('dlqmygoods');
        return {
            code: 200,
            msg: '查找成功',
            data: result
        };
    }
    async findAllMyinvitation() {
        const result = await this.app.mysql.select('dlqinvitation');
        return {
            code: 200,
            msg: '查找成功',
            data: result
        };
    }
    async findAllFans() {
        const result = await this.app.mysql.select('dlqfans');
        return {
            code: 200,
            msg: '查找成功',
            data: result
        };
    }
    async findAllAutoreply() {
        const result = await this.app.mysql.select('dlqautoreply');
        return {
            code: 200,
            msg: '查找成功',
            data: result
        };
    }
    async find(uid) {
        const result = await this.app.mysql.get('dlqusers', { id: uid });
        if (result !== null) {
            return {
                code: 200,
                msg: '查找成功',
                data: result
            };
        } else {
            return {
                msg: '没有此条数据！'
            }
        }

    }
    async findOther(uid) {
        const result = await this.app.mysql.get('dlqusers', { id: uid });
        if (result !== null) {
            return {
                code: 200,
                msg: '查找成功',
                data: result
            };
        } else {
            return {
                msg: '没有此用户！'
            }
        }

    }
    async create(params) {
        const cfg = {
            time: params.time,
            name: params.name,
            info: params.info,
            purpose: params.purpose,
            evaluate: params.evaluate
        }
        const result = await this.app.mysql.insert('dlqcenter', cfg);
        return {
            code: 200,
            msg: '创建成功',
            data: result
        };
    }
    async delete(uid) {
        const result = await this.app.mysql.delete('dlqcenter', { id: uid });
        return {
            code: 200,
            msg: '删除成功',
            data: result
        };
    }
    async update(uid, params) {
        const cfg = {
            id: uid,
            time: params.time,
            name: params.name,
            info: params.info,
            purpose: params.purpose,
            evaluate: params.evaluate
        }
        const result = await this.app.mysql.update('dlqcenter', cfg)
        return {
            code: 200,
            msg: '更新成功',
            data: result
        }
    }
    async updateFans(params) {
        const cfg = {
            id: params.id,
            attention: params.attention
        }
        const result = await this.app.mysql.update('dlqfans', cfg)
        return {
            code: 200,
            msg: '更新成功',
            data: result
        }
    }
    async updateReplyChange(params) {
        const cfg = {
            id: params.id,
            value: params.value
        }
        const result = await this.app.mysql.update('dlqautoreply', cfg)
        return {
            code: 200,
            msg: '更新成功',
            data: result
        }
    }
    async updateReply(params) {
        const cfg = {
            id: params.id,
            reply: params.reply
        }
        const result = await this.app.mysql.update('dlqautoreply', cfg)
        return {
            code: 200,
            msg: '更新成功',
            data: result
        }
    }
    async updatePassword(params) {
        const cfg = {
            id: params.id,
            password: params.password
        }
        const result = await this.app.mysql.update('dlqusers', cfg)
        return {
            code: 200,
            msg: '更新成功',
            data: result
        }
    }
    async updatePhone(params) {
        const cfg = {
            id: params.id,
            phone: params.phone
        }
        const result = await this.app.mysql.update('dlqusers', cfg)
        return {
            code: 200,
            msg: '更新成功',
            data: result
        }
    }
}

module.exports = dlqcenter;